<?php 
@session_start();

class AdminLogIn {
	public static function LogInForm() {
		echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Logowanie do CAD Admin Panel</title>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<style>
		*{ FONT-SIZE: 8pt; FONT-FAMILY: verdana; } 
		b { FONT-WEIGHT: bold; } 
		.listtitle { BACKGROUND: #425984; COLOR: #EEEEEE; white-space: nowrap; } 
		td.list { BACKGROUND: #EEEEEE; white-space: nowrap; } 
		input.mybutton { font-size:9px; font-family:Arial,sans-serif; font-weight:bold; color:#444444; background-color:#EEEEEE; border-style:double; border-color:#999999; border-width:3px; } 
	</style>
';
		if (isset($_SESSION['LoginError']) && $_SESSION['LoginError']) {
			echo '<script language="javascript"> alert("' . $_SESSION['LoginError'] .'")</script>';
			unset($_SESSION['LoginError']);
		}
		echo'
</head>
<body onLoad="document.getElementById(\'AdminLogin\').focus();">
	<center><br /><br /><br /><br />
	<h1>IT-World Admin Panel</h1>
	<table cellspacing=1 cellpadding=5>
		<tr><td class=listtitle align="center" colspan=2>Podaj nazwę użytkownika i hasło</td></tr>
		<form action="dbAction/LoginCheck.php" method="post" name="form">
			<tr><td class="list" align="right">Użytkownik:</td> <td class=list><input type="text" name="AdminLogin" id="AdminLogin"/></td></tr>
			<tr><td class="list" align="right">Hasło:</td>      <td class=list><input type="password" name="AdminPass" /></td></tr>
			<tr><td class="listtitle" align="center" colspan=2><input type="submit" class="mybutton" value="Login" /></td></tr>     
		</form>
	</table>
	</center>
</body>
</html>';
	}
	
	public static function IsLoggedIn() {
  		global $_SESSION;
  		if (isset($_SESSION['UserId']) && $_SESSION['UserId'])
    		return true;
  		else
    		return false;
	}
	
	public static function IsAdmin() {
		global $_SESSION;
		$MyResult = false;
		if(AdminLogIn::IsLoggedIn())
		{
			@include_once('./dbAction/DbConn.php'); //w zależności od miejsca, gdzie zostanie zainclude'owane 
			@include_once('./DbConn.php');
			$MyConn = DbConn::GetDbConn();
			if(!is_null($MyConn))
			{
				if($MyResult = $MyConn->query('SELECT * FROM users_groups_con WHERE `USERS_ID`=' . $_SESSION['UserId'] . 
					' AND `USERS_GROUPS_ID` = (SELECT `USERS_GROUPS_ID` FROM users_groups WHERE `KEY`=\'ADMIN\')'))
				{
					if($MyResult->num_rows > 0)
						$MyResult = true;	
					
					//$MyResult->close();
				}
				$MyConn->close();
			}
		}
		return $MyResult;
	}
}
?>